/**
 * 封装Select
 * @author SPY
 * @date 2020/1/17
 */

import React from 'react';
import PropTypes from 'prop-types';
import { Select } from 'antd';

// 定义页面级变量
const { Option } = Select;

class MySelect extends React.Component {

    // 定义传入属性
    static propTypes = {
        options: PropTypes.array.isRequired,  // 需要展示的select数据
        placeholder: PropTypes.string,
    }

    // 定义传入属性的默认值
    static defaultProps = {
        options: [],
        placeholder: '请选择',
    }

    renderSelect = (item) => {
        return (
            <Option key={item.value} value={item.value}>{item.label}</Option>
        );
    }


    render() {
        const { options, placeholder, ...restProps } = this.props;
        return (
            <Select
                placeholder={placeholder}
                {...restProps}
            >
                {
                    Array.isArray(options) && options.length > 0 && options.map(this.renderSelect)
                }
            </Select>
        );
    }
}

export default MySelect;